namespace TS2015.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class change : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.TbChucNang_Quyen",
                c => new
                    {
                        MaQuyen = c.Int(nullable: false),
                        MaCN = c.Int(nullable: false),
                        TrangThai = c.Boolean(),
                    })
                .PrimaryKey(t => new { t.MaQuyen, t.MaCN })
                .ForeignKey("dbo.TbChucNang", t => t.MaCN)
                .ForeignKey("dbo.TbLoaiND", t => t.MaQuyen)
                .Index(t => t.MaQuyen)
                .Index(t => t.MaCN);
            
            CreateTable(
                "dbo.TbChucNang",
                c => new
                    {
                        MaCN = c.Int(nullable: false, identity: true),
                        TenCN = c.String(maxLength: 50),
                        Link = c.String(maxLength: 500, unicode: false),
                        MoTa = c.String(maxLength: 500),
                        MaCNCha = c.Int(),
                        TrangThai = c.Int(),
                        Anh = c.String(maxLength: 100, unicode: false),
                    })
                .PrimaryKey(t => t.MaCN);
            
            CreateTable(
                "dbo.TbLoaiND",
                c => new
                    {
                        MaLoaiND = c.Int(nullable: false, identity: true),
                        Quyen = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(),
                    })
                .PrimaryKey(t => t.MaLoaiND);
            
            CreateTable(
                "dbo.TbNguoiDung",
                c => new
                    {
                        TenDangNhap = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaLoaiND = c.Int(nullable: false),
                        MatKhau = c.String(nullable: false, maxLength: 32, fixedLength: true),
                        Email = c.String(maxLength: 50),
                        RandomPass = c.String(nullable: false, maxLength: 8),
                        KhoaTaiKhoan = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.TenDangNhap)
                .ForeignKey("dbo.TbLoaiND", t => t.MaLoaiND)
                .Index(t => t.MaLoaiND);
            
            CreateTable(
                "dbo.TbChuyenNganh",
                c => new
                    {
                        MaChuyenNganh = c.Int(nullable: false, identity: true),
                        MaNganh = c.Int(nullable: false),
                        TenChuyenNganh = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(),
                    })
                .PrimaryKey(t => t.MaChuyenNganh)
                .ForeignKey("dbo.TbNganh", t => t.MaNganh)
                .Index(t => t.MaNganh);
            
            CreateTable(
                "dbo.TbNganh",
                c => new
                    {
                        MaNganh = c.Int(nullable: false, identity: true),
                        MaKhoa = c.Int(nullable: false),
                        TenNganh = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(),
                    })
                .PrimaryKey(t => t.MaNganh)
                .ForeignKey("dbo.TbKhoa", t => t.MaKhoa)
                .Index(t => t.MaKhoa);
            
            CreateTable(
                "dbo.TbKhoa",
                c => new
                    {
                        MaKhoa = c.Int(nullable: false, identity: true),
                        TenKhoa = c.String(nullable: false, maxLength: 50),
                        MoTa = c.String(),
                    })
                .PrimaryKey(t => t.MaKhoa);
            
            CreateTable(
                "dbo.TbThiSinh",
                c => new
                    {
                        MaTS = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaTruong = c.Int(nullable: false),
                        MaKhuVuc = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaXepLoaiHS = c.Int(),
                        HoDem = c.String(nullable: false, maxLength: 50),
                        Ten = c.String(nullable: false, maxLength: 50),
                        GioiTinh = c.String(nullable: false, maxLength: 3, fixedLength: true),
                        NgaySinh = c.DateTime(nullable: false),
                        Email = c.String(maxLength: 50),
                        SoDienThoai = c.String(maxLength: 11, fixedLength: true),
                        MaDanToc = c.Int(nullable: false),
                        QueQuan = c.String(nullable: false, maxLength: 50),
                        DiaChi = c.String(nullable: false, maxLength: 50),
                        CMND = c.String(nullable: false, maxLength: 15, fixedLength: true),
                        CoQuanCongTac = c.String(nullable: false, maxLength: 50),
                        DiemLop10 = c.Double(),
                        DiemLop11 = c.Double(),
                        DiemTBTHPT = c.Double(),
                        DiemLop12 = c.Double(),
                        DiemTBTN = c.Double(),
                        NamTotNghiep = c.String(nullable: false, maxLength: 4, fixedLength: true),
                        NoiTotNghiep = c.String(nullable: false, maxLength: 50),
                        Anh = c.String(nullable: false, maxLength: 100, unicode: false),
                        MaDoiTuong = c.Int(nullable: false),
                        MaKhoiThi = c.Int(nullable: false),
                        MaHeDaoTao = c.Int(nullable: false),
                        MaKhoa = c.Int(nullable: false),
                        TrangThaiDongTien = c.Boolean(),
                        TrangThaiDangKi = c.Boolean(),
                        TrangThaiHoanThanh = c.Boolean(),
                        NgayDangKi = c.DateTime(nullable: false),
                        NgayDongTien = c.DateTime(),
                        NgayHoanThanhDK = c.DateTime(),
                        LanSuaCuoi = c.DateTime(),
                    })
                .PrimaryKey(t => t.MaTS)
                .ForeignKey("dbo.TbDoiTuongUuTien", t => t.MaDoiTuong)
                .ForeignKey("dbo.TbHeDaoTao", t => t.MaHeDaoTao, cascadeDelete: true)
                .ForeignKey("dbo.TbKhoa", t => t.MaKhoa, cascadeDelete: true)
                .ForeignKey("dbo.TbKhoiThi", t => t.MaKhoiThi)
                .Index(t => t.MaDoiTuong)
                .Index(t => t.MaKhoiThi)
                .Index(t => t.MaHeDaoTao)
                .Index(t => t.MaKhoa);
            
            CreateTable(
                "dbo.TbDoiTuongUuTien",
                c => new
                    {
                        MaDoiTuong = c.Int(nullable: false, identity: true),
                        TenDoiTuong = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaDoiTuong);
            
            CreateTable(
                "dbo.TbHeDaoTao",
                c => new
                    {
                        MaHeDaoTao = c.Int(nullable: false, identity: true),
                        TenHeDaoTao = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaHeDaoTao);
            
            CreateTable(
                "dbo.TbKhoiThi",
                c => new
                    {
                        MaKhoiThi = c.Int(nullable: false, identity: true),
                        TenKhoiThi = c.String(nullable: false, maxLength: 15, fixedLength: true),
                    })
                .PrimaryKey(t => t.MaKhoiThi);
            
            CreateTable(
                "dbo.TbDiemTotNghiep",
                c => new
                    {
                        MaTS = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        MaMon = c.Int(nullable: false),
                        Diem = c.Double(nullable: false),
                    })
                .PrimaryKey(t => new { t.MaTS, t.MaMon })
                .ForeignKey("dbo.TbMonTotNghiep", t => t.MaMon)
                .Index(t => t.MaMon);
            
            CreateTable(
                "dbo.TbMonTotNghiep",
                c => new
                    {
                        MaMon = c.Int(nullable: false, identity: true),
                        TenMon = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaMon);
            
            CreateTable(
                "dbo.TbHuyen",
                c => new
                    {
                        MaHuyen = c.Int(nullable: false, identity: true),
                        MaTinh = c.Int(nullable: false),
                        TenHuyen = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaHuyen)
                .ForeignKey("dbo.TbTinh", t => t.MaTinh, cascadeDelete: true)
                .Index(t => t.MaTinh);
            
            CreateTable(
                "dbo.TbTinh",
                c => new
                    {
                        MaTinh = c.Int(nullable: false, identity: true),
                        TenTinh = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaTinh);
            
            CreateTable(
                "dbo.TbTruong",
                c => new
                    {
                        MaTruong = c.Int(nullable: false, identity: true),
                        TenTruong = c.String(nullable: false, maxLength: 50),
                        MaTỉnh = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaTruong)
                .ForeignKey("dbo.TbTinh", t => t.MaTỉnh)
                .Index(t => t.MaTỉnh);
            
            CreateTable(
                "dbo.TbKhuVuc",
                c => new
                    {
                        MaKhuVuc = c.String(nullable: false, maxLength: 10, fixedLength: true),
                        TenKhuVuc = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaKhuVuc);
            
            CreateTable(
                "dbo.TbLoaiTinTuc",
                c => new
                    {
                        MaLoaiTinTuc = c.Int(nullable: false, identity: true),
                        Anh = c.String(maxLength: 100, unicode: false),
                        TenLoaiTinTuc = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaLoaiTinTuc);
            
            CreateTable(
                "dbo.TbTinTuc",
                c => new
                    {
                        MaTinTuc = c.Long(nullable: false, identity: true),
                        TieuDe = c.String(nullable: false, maxLength: 200),
                        AnhDaiDien = c.String(maxLength: 100, unicode: false),
                        MoTa = c.String(maxLength: 500),
                        NoiDung = c.String(nullable: false, storeType: "ntext"),
                        NgayDang = c.DateTime(nullable: false),
                        MaLoaiTinTuc = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.MaTinTuc)
                .ForeignKey("dbo.TbLoaiTinTuc", t => t.MaLoaiTinTuc)
                .Index(t => t.MaLoaiTinTuc);
            
            CreateTable(
                "dbo.TbSlide",
                c => new
                    {
                        MaSlide = c.Int(nullable: false, identity: true),
                        MoTa = c.String(maxLength: 1000),
                        Anh = c.String(maxLength: 100, unicode: false),
                        ThuTu = c.Int(),
                    })
                .PrimaryKey(t => t.MaSlide);
            
            CreateTable(
                "dbo.TbThongBao",
                c => new
                    {
                        NoiDung = c.String(storeType: "ntext"),
                        IdThongBao = c.Long(nullable: false, identity: true),
                        NguoiGui = c.String(maxLength: 10, fixedLength: true),
                        NguoiNhan = c.String(maxLength: 10, fixedLength: true),
                        NgayGui = c.DateTime(nullable: false),
                        TrangThai = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.IdThongBao);
            
            CreateTable(
                "dbo.TbXepLoaiHS",
                c => new
                    {
                        MaXepLoaiHS = c.Int(nullable: false),
                        TenXepLoai = c.String(nullable: false, maxLength: 50),
                    })
                .PrimaryKey(t => t.MaXepLoaiHS);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.TbTinTuc", "MaLoaiTinTuc", "dbo.TbLoaiTinTuc");
            DropForeignKey("dbo.TbTruong", "MaTỉnh", "dbo.TbTinh");
            DropForeignKey("dbo.TbHuyen", "MaTinh", "dbo.TbTinh");
            DropForeignKey("dbo.TbDiemTotNghiep", "MaMon", "dbo.TbMonTotNghiep");
            DropForeignKey("dbo.TbThiSinh", "MaKhoiThi", "dbo.TbKhoiThi");
            DropForeignKey("dbo.TbThiSinh", "MaKhoa", "dbo.TbKhoa");
            DropForeignKey("dbo.TbThiSinh", "MaHeDaoTao", "dbo.TbHeDaoTao");
            DropForeignKey("dbo.TbThiSinh", "MaDoiTuong", "dbo.TbDoiTuongUuTien");
            DropForeignKey("dbo.TbNganh", "MaKhoa", "dbo.TbKhoa");
            DropForeignKey("dbo.TbChuyenNganh", "MaNganh", "dbo.TbNganh");
            DropForeignKey("dbo.TbNguoiDung", "MaLoaiND", "dbo.TbLoaiND");
            DropForeignKey("dbo.TbChucNang_Quyen", "MaQuyen", "dbo.TbLoaiND");
            DropForeignKey("dbo.TbChucNang_Quyen", "MaCN", "dbo.TbChucNang");
            DropIndex("dbo.TbTinTuc", new[] { "MaLoaiTinTuc" });
            DropIndex("dbo.TbTruong", new[] { "MaTỉnh" });
            DropIndex("dbo.TbHuyen", new[] { "MaTinh" });
            DropIndex("dbo.TbDiemTotNghiep", new[] { "MaMon" });
            DropIndex("dbo.TbThiSinh", new[] { "MaKhoa" });
            DropIndex("dbo.TbThiSinh", new[] { "MaHeDaoTao" });
            DropIndex("dbo.TbThiSinh", new[] { "MaKhoiThi" });
            DropIndex("dbo.TbThiSinh", new[] { "MaDoiTuong" });
            DropIndex("dbo.TbNganh", new[] { "MaKhoa" });
            DropIndex("dbo.TbChuyenNganh", new[] { "MaNganh" });
            DropIndex("dbo.TbNguoiDung", new[] { "MaLoaiND" });
            DropIndex("dbo.TbChucNang_Quyen", new[] { "MaCN" });
            DropIndex("dbo.TbChucNang_Quyen", new[] { "MaQuyen" });
            DropTable("dbo.TbXepLoaiHS");
            DropTable("dbo.TbThongBao");
            DropTable("dbo.TbSlide");
            DropTable("dbo.TbTinTuc");
            DropTable("dbo.TbLoaiTinTuc");
            DropTable("dbo.TbKhuVuc");
            DropTable("dbo.TbTruong");
            DropTable("dbo.TbTinh");
            DropTable("dbo.TbHuyen");
            DropTable("dbo.TbMonTotNghiep");
            DropTable("dbo.TbDiemTotNghiep");
            DropTable("dbo.TbKhoiThi");
            DropTable("dbo.TbHeDaoTao");
            DropTable("dbo.TbDoiTuongUuTien");
            DropTable("dbo.TbThiSinh");
            DropTable("dbo.TbKhoa");
            DropTable("dbo.TbNganh");
            DropTable("dbo.TbChuyenNganh");
            DropTable("dbo.TbNguoiDung");
            DropTable("dbo.TbLoaiND");
            DropTable("dbo.TbChucNang");
            DropTable("dbo.TbChucNang_Quyen");
        }
    }
}
